<template>
  <base-layout
    :dialog-visible="dialogVisible"
    dialog-title="调拨详情"
    @dialog-close="dialogClose"
    dialogWidth="1000px"
  >
    <template #searchPanel>
      <search-panel
        ref="searchPanel"
        addTitle="新增调拨"
        @search="search"
        :addPer="authConfig.add"
        :selectPer="authConfig.query"
        @insert="addHandle"
        :showAddButton="true"
      >
        <el-select clearable v-model="form.outStoreId" placeholder="调拨门店">
          <el-option
            v-for="item in allStores"
            :key="item.id"
            :value="item.id"
            :label="item.storeName"
          />
        </el-select>
        <!-- <job-shop v-model="form.outStoreId" placeholder="调拨门店" /> -->
        <job-shop v-model="form.inStoreId" placeholder="收货门店" />
        <el-date-picker
          v-model="form.dateList"
          type="datetimerange"
          start-placeholder="调拨开始日期"
          end-placeholder="调拨结束日期"
          clearable
          value-format="yyyy-MM-dd hh:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
        />
      </search-panel>
    </template>

    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        @row-dblclick="rowDblclick"
        :width="160"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit pointer ml-20"
            title="编辑"
            v-permission="authConfig.edit"
            @click="editHandle(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete pointer ml-20"
            title="删除"
            v-permission="authConfig.del"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
      <!--工具条-->
    </template>
    <template #dialog>
      <transfer-view :value="dialogData" @back-status="backStatus"/>
    </template>
  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
// import { getDict } from '@/utils/index'
import TransferView from './components/transferView'
import {
  dataList,
  deleteData,
  details,
} from '@/api/pre-sale/boutiqueStock/transferManagement'
// import { parseTimeToYMDHMS } from '@/utils'
import { mapGetters } from 'vuex'

// 采购申请页面
export default {
  components: {
    TransferView,
  },
  computed: {
    ...mapGetters(['allStores']),
  },
  mixins: [
    baseMixin({
      findData: dataList,
      dataName: ['content', 'totalRecords'],
      deleteData: deleteData,
      findDataById: details,
      idName: 'id',
      format(res) {
        return res.map((data) => {
          // data.createTime = data.createTime ? parseTimeToYMDHMS(data.createTime) : ''
          return data
        })
      },
    }),
  ],
  data() {
    return {
      authConfig: {
        query: 'brandAllot:page',
        add: 'brandAllot:save',
        edit: 'brandAllot:update',
        del: 'brandAllot:del',
        detail: 'brandAllot:detail'
      },
      form: {
        outStoreId: '',
        inStoreId: '',
        dateList: [],
      },
      dialogVisible: false,
      tableColumnAttributes: [
        { name: '调拨门店', value: 'outStoreName', type: 'text' },
        { name: '调拨单号', value: 'code', type: 'text' },
        { name: '出库仓库', value: 'outStorageName', type: 'text' },
        { name: '调拨精品数量', value: 'num', type: 'text' },
        { name: '精品总金额', value: 'amount', type: 'text' },
        { name: '调拨时间', value: 'receiptsTime', type: 'text' },
        { name: '收货门店', value: 'storeName', type: 'text' },
        { name: '收货仓库', value: 'inStorageName', type: 'text' },
        { name: '状态', value: 'status', type: 'text' },
        { name: '调拨负责人', value: 'userName', type: 'text' },
        { name: '负责人联系方式', value: 'phone', type: 'text' },
        { name: '备注', value: 'remark', type: 'text' },
        { name: '录入时间', value: 'createTime', type: 'text' },
      ],
      tableData: [],
      detailData: null,
    }
  },

  methods: {
    // 新增调拨
    addHandle() {
      this.$router.push({ name: 'transferAdd', params: { id: 0 } })
    },
    // 编辑调拨
    editHandle(row) {
      this.$router.push({ name: `transferEdit`, params: { id: row.id } })
    },
    // 查看调拨记录
    rowDblclick(row) {
      this.handleDataChange(row)
    },
    backStatus(){
      this.setTableData()
      this.dialogClose();
    },
    // 搜索
    search() {
      const { inStoreId = '', outStoreId = '', dateList = [] } = this.form
      this.searchOptions = {
        inStoreId,
        outStoreId,
        allotStartTime: dateList && dateList.length > 0 ? dateList[0] : '',
        allotEndTime: dateList && dateList.length > 0 ? dateList[1] : '',
      }
      this.currentPage = 1
      this.setTableData()
    },
  },
  created() {},
  mounted() {},
}
</script>

<style lang="scss" scoped></style>
